#include "Library.hpp"

#include <stdio.h>
#include <sstream>
#include <Windows.h>

double Library::configuration_distance(ConfSet a,ConfSet b)
{
	if(a.size()!=b.size())
	{
		printf("Incompatible confsets\n");
		throw 1;
	}
	double total_distance=0;
	for(UINT32 i=0;i<a.size();i++)
	{
		Point_2 point_a=a[i];
		Point_2 point_b=b[i];
		double a_x = CGAL::to_double(point_a.x());
		double a_y = CGAL::to_double(point_a.y());
		double b_x = CGAL::to_double(point_b.x());
		double b_y = CGAL::to_double(point_b.y());

		total_distance+=sqrt(pow(a_x-b_x, 2) + pow(a_y - b_y,2));
	}
	return total_distance;
}

std::string Library::conf_to_string(ConfSet a)
{
	stringstream ss;
	Point_2 point_a=a[0];
	Point_2 point_b=a[1];
	double a_x = CGAL::to_double(point_a.x());
	double a_y = CGAL::to_double(point_a.y());
	double b_x = CGAL::to_double(point_b.x());
	double b_y = CGAL::to_double(point_b.y());
	ss<<"("<<a_x<<","<<a_y<<")-("<<b_x<<","<<b_y<<")";
	return ss.str();
}